#include <stdio.h>

int primeFactors4(int n)
{
	int num = 0, i=2, flag=0;
	while (n>1) {
		while(n%i == 0) {
			n/=i;
			flag = 1;
		}
		if (flag)num++;
		flag = 0;
		i++;
	}
	return num==4;
}

int main()
{
	int i;
	//printf("%d\n", primeFactors4(1000));
	for (i=1000; i<1000000; i++) {
		//if (primeFactors4(i))printf("%d ", i);
		if (primeFactors4(i) && primeFactors4(i+1) 
		    && primeFactors4(i+2) && primeFactors4(i+3))break;
	}
	printf("\n%d\n", i);
}
